/* fmpsrp10.p - ITEM-SITE FORMULA STRUCTURE REPORT                            */
/* Copyright 1986-2006 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* REVISION: 8.5          CREATED: 06/26/96 BY: *G1YQ* Julie Milligan         */
/* REVISION: 8.6    LAST MODIFIED: 10/15/97 BY: ays    *K10L*                 */
/* REVISION: 7.4         MODIFIED: 02/05/98 BY: *H1JC* Jean Miller            */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98 BY: *L007* A. Rahane              */
/* REVISION: 8.6E   LAST MODIFIED: 07/22/98 BY: *L04D* Russ Witt              */
/* REVISION: 9.0    LAST MODIFIED: 09/22/98 BY: *J30L* Raphael T.             */
/* REVISION: 9.0    LAST MODIFIED: 02/12/99 BY: *M080* Prashanth Narayan      */
/* REVISION: 9.0    LAST MODIFIED: 03/13/99 BY: *M0BD* Alfred Tan             */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane       */
/* REVISION: 9.1    LAST MODIFIED: 08/14/00 BY: *N0L0* Jacolyn Neder          */
/* Revision: 1.16         BY: Jean Miller          DATE: 04/25/02 ECO: *P06H* */
/* Revision: 1.18         BY: Paul Donnelly (SB)   DATE: 06/26/03 ECO: *Q00C* */
/* Revision: 1.19.1.1     BY: Gaurav Kerkar        DATE: 12/18/06 ECO: *P5JD* */
/* $Revision: 1.19.1.2 $    BY: Jason Zhang          DATE: 09/26/08 ECO: *KYA4* */
/*-Revision end---------------------------------------------------------------*/
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*V8:ConvertMode=FullGUIReport                                                */

{mfdtitle.i "99 "}

define variable parent1    like ps_par no-undo.
define variable parent2    like ps_par no-undo.
define variable op         like ro_op format ">>>>>>" no-undo.
define variable op1        like ro_op format ">>>>>>" no-undo.
define variable skpge      like mfc_logical initial no
                           label "New Page Each Parent" no-undo.
define variable sort_ref   like mfc_logical initial no
                           label "Sort by Reference" no-undo.
define variable site       like ptp_site no-undo.
define variable comp       like ps_comp no-undo.
define variable level      as integer no-undo.
define variable maxlevel   as integer format ">>>" label "Levels" no-undo.
define variable eff_date   like exr_start_date
                           label "Begin Date" no-undo.
define variable parent     like ps_par no-undo.
define variable desc1      like pt_desc1 format "x(24)" no-undo.
define variable um         like pt_um no-undo.
define variable phantom    like mfc_logical format "yes" label "Ph" no-undo.
define variable iss_pol    like pt_iss_pol format "/no" no-undo.
define variable lvl        as character format "x(10)" label "Level" no-undo.
define variable new_parent like mfc_logical no-undo.
define variable lines      as integer no-undo.
define variable bom_code   like pt_bom_code no-undo.
define variable batch_size like bom_batch no-undo.
define variable first-time as logical no-undo initial "yes".
define variable formula_only like mfc_logical initial no
                             label "Formula Only" no-undo.
/*KYA4*/ define variable altpart  like ptal_alt_part no-undo.
/*KYA4*/ define variable altpart1 like ptal_alt_part no-undo.


define frame det2.
{fmpsrp10.i}
assign
   site     = global_site
   eff_date = today.

form
   parent1        colon 22
   parent2        label {t001.i} colon 49 skip
   op             colon 22
   op1            label {t001.i} colon 49
/*KYA4*/ altpart        colon 22
/*KYA4*/ altpart1       label {t001.i} colon 49 skip (1)
   site           colon 22 skip
   eff_date       colon 22 skip
   maxlevel       colon 22 skip
   skpge          colon 22 skip
   sort_ref       colon 22 skip
   formula_only   colon 22 skip
with frame a width 80 side-labels attr-space.

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

{wbrp01.i}

repeat:

   first-time = yes.

   if parent2 = hi_char then parent2 = "".
   if op1 = 999999 then op1 = 0.
/*KYA4*/   if altpart1 = hi_char then altpart1 = "".

   if c-application-mode <> "WEB" then
      update
         parent1
         parent2
         op
         op1
/*KYA4*/ altpart
/*KYA4*/ altpart1
         site
         eff_date
         maxlevel
         skpge
         sort_ref
         formula_only
      with frame a.

/*KYA4*/   {wbrp06.i &command = update &fields = "  parent1 parent2
         altpart altpart1 op op1 site eff_date maxlevel
         skpge sort_ref formula_only" &frm = "a"}

   if (c-application-mode <> "WEB") or
      (c-application-mode = "WEB" and
      (c-web-request begins "DATA")) then do:

      bcdparm = "".
/*KYA4*/  {gprun.i ""gpquote.p"" "(input-output bcdparm,11,
           parent1,parent2,string(op),string(op1),altpart,altpart1,
           site,string(eff_date),string(maxlevel),
           string(skpge),string(sort_ref),string(formula_only),
           null_char, null_char, null_char, null_char,
           null_char, null_char, null_char, null_char)"}

      if parent2 = "" then parent2 = hi_char.
      if op1 = 0 then op1 = 999999.
/*KYA4*/ if altpart1 = "" then altpart1 = hi_char.

      /* Add this do loop so the converter will not create 'on leave' */
      do:
         if not can-find(si_mstr   where si_mstr.si_domain = global_domain and
         si_site = site) then do:
            {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3} /* SITE DOES NOT EXIST. */
            if c-application-mode = "WEB" then return.
            else
               next-prompt site with frame a.
            undo, retry.
         end.
      end.

   end. /*if c-application-mode */

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
   {mfphead.i}

   form
      site skip(1)
   with frame a1 width 132 page-top side-labels.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame a1:handle).
   display site with frame a1.

   for each pt_mstr no-lock
       where pt_mstr.pt_domain = global_domain and  pt_part >= parent1 and
       pt_part <= parent2:

/*KYA4*/    find first ptal_mstr where ptal_mstr.ptal_domain = global_domain
/*KYA4*/                           and ptal_part             = pt_part
/*KYA4*/                           and ptal_active
/*KYA4*/                           no-lock no-error.

/*KYA4*/    if (not available ptal_mstr)
/*KYA4*/       or ptal_mstr.ptal_alt_part < altpart
/*KYA4*/       or ptal_mstr.ptal_alt_part > altpart1
/*KYA4*/       then do:
/*KYA4*/          if altpart <> "" or altpart1 <> hi_char then
/*KYA4*/             next.
/*KYA4*/       end.

      assign
         comp     = pt_part
         phantom  = pt_phantom
         bom_code = if pt_bom_code <> "" then pt_bom_code else pt_part
         maxlevel = min(maxlevel,99)
         level    = 1.

      find ptp_det no-lock  where ptp_det.ptp_domain = global_domain and
      ptp_part = pt_part
         and ptp_site = site no-error.
      if available ptp_det then
         bom_code = if ptp_bom_code <> "" then ptp_bom_code else ptp_part.


      assign
         comp    = bom_code
         parent  = pt_part
         phantom = if available ptp_det then ptp_phantom else phantom
         iss_pol = if available ptp_det then ptp_iss_pol else pt_iss_pol
         new_parent = yes.

      for first bom_mstr
      fields(bom_domain bom_batch bom_batch_um bom_desc bom_formula bom_parent)
         where bom_mstr.bom_domain = global_domain
         and   bom_parent = bom_code
         and   (formula_only = no
                or bom_formula)
      no-lock:
      end. /* FOR FIRST bom_mstr */

      if not available bom_mstr
      then
         next.
      else do:
         if c-application-mode <> "WEB"
         then
            view frame phead.

         /* Changed entire logic to Recursive calling of Internal Procedure */
         run process_report (input comp,input level, input new_parent).

         {mfrpchk.i}

      end. /* IF AVAILABLE bom_mstr */

   end. /* FOR EACH pt_mstr */

   /* REPORT TRAILER */
   {mfrtrail.i}

   global_site = site.
end.

{wbrp04.i &frame-spec = a}
